import { Response } from 'express'
import {commonResponse} from "../utils/commonResponse";
import {IPromiseCommonResponse, ISqlInsert, tokenParams} from "../../global";
import {parseToken} from "../utils/jwt";
import {expertAddDao, expertList, IExpert} from "../dao/expertDao";


export const expertListService = async (res: Response, token: string) => {
    return await commonResponse<IPromiseCommonResponse<Array<IExpert>>, Array<IExpert>>(res, async () => {
        const params = parseToken(token)
        return Promise.resolve({ code: 200, data: await expertList([(params as tokenParams).userUID]) })
    })
}

export const expertAddService = async (res: Response, params: Array<string>) => {
    return await commonResponse<IPromiseCommonResponse<ISqlInsert>, ISqlInsert>(res, async () => {
        return Promise.resolve({ code: 200, data: await expertAddDao(params) })
    })
}